class ConnectionPool
  def initialize count, opts
    @pool = []
    @waiting = []
    count.times { @pool << Asymy::Connection.new(opts) }
  end

  def check_if_can_run
        if @pool.length > 0 and @waiting.length > 0
                conn = @pool.shift
                query, block = @waiting.shift
                conn.exec(query) {|*args|
                        block.call *args
                        @pool << conn
                        check_if_can_run # seems to work with a large pool--we'll call it good
                }
                #               check_if_can_run # not sure if this is necessary ever or not...
        end
  end

  def exec_when_available query, &block
        @waiting << [query, block]
        check_if_can_run
  end
end

